home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #19 (Apr 87) / help demo.c / atoi.c next >
Text File  |  1987-02-02  |  811b  |  38 lines

  1. /***********************************************************************
  2.  * atoi.c - much smaller than unix & stdio libraries 
  3.  *
  4.  * WN Rausch
  5.  * January 1987
  6.  **********************************************************************/
  7.  
  8. #include <MacTypes.h>
  9. #include <pascal.h>
  10. #include <strings.h>
  11.  
  12. #define isspace(c) (c == ' ' || c == '\t')
  13. #define ZERO 48
  14.  
  15. /**********************************************************************/
  16. atoi(string)
  17. register char *string;   /* must be NULL terminated */
  18.   {
  19.   register long answer = 0L;
  20.   Boolean negative = FALSE;
  21.   
  22.   while (isspace(*string))
  23.       string++;
  24.       
  25.   if (*string == '-')
  26.       negative = TRUE;
  27.       
  28.   while (*string)
  29.       {
  30.       answer = (answer * 10) + (*string - ZERO);
  31.       string++;
  32.       }
  33.       
  34.   if (negative)
  35.       answer = 0 - answer;
  36.   
  37.   return (int)answer;
  38.   }